package mi.paq;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class PruebaDBActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    public void onClickEvent(View v)
    {

    	Toast.makeText(this, "Buscando datos",Toast.LENGTH_SHORT).show();
    	
    	TextView text1 = (TextView)findViewById(R.id.textView1);
    	
    	Integer cantPlatos=PlatosDAO.getCantPlatos(1);
    	
    	text1.setText(cantPlatos.toString());
    	
    	
    }
    
    
    public void Cosas() {
    	
    	Toast.makeText(this, "Buscando datos",Toast.LENGTH_SHORT).show();
    	
    	TextView text1 = (TextView)findViewById(R.id.textView1);
    	
    	
    	String urlConex="jdbc:mysql://192.168.1.103:3306/db_resto";
    	  	
    	try {
    		Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection(urlConex, "gr3atmov3", "nocdfound");
			Statement select = 	con.createStatement();
			ResultSet result = select.executeQuery("Select * from platos");
			
			String valor;
			result.next();
			valor=result.getString(2).toString();
			
			
			text1.setText(valor);
			
			select.close();
			con.close();
			
			
		} catch (Exception e) {
			Log.w("SQL", "No funca: "+ e.getMessage());

			Toast.makeText(this, "E2",Toast.LENGTH_SHORT).show();
		}
	}
    
}